/**
 * MOTOR 2 - RAPID FLASH DYNAMICS
 * Copyright (c) 2007-2008, Michael Baczynski
 * Based on the Box2D Engine by Erin Catto, http://www.box2d.org
 * 
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 * 
 * * Redistributions of source code must retain the above copyright notice,
 *   this list of conditions and the following disclaimer.
 * * Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 * * Neither the name of the polygonal nor the names of its contributors may be
 *   used to endorse or promote products derived from this software without specific
 *   prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package de.polygonal.motor2.collision.pairwise
{
	public class FeaturePair
	{
		public static const NO_EDGE:int = 0;
		
		public var inEdge1:int, outEdge1:int;
		public var inEdge2:int, outEdge2:int;
		
		public function FeaturePair(source:FeaturePair = null)
		{
			if (source)
			{
				inEdge1 = source.inEdge1;
				inEdge2 = source.inEdge2;
				
				outEdge1 = source.outEdge1;
				outEdge2 = source.outEdge2;
			}
			else
			{
				inEdge1 = outEdge1 = inEdge2 = outEdge2 = NO_EDGE;
			}
		}
		
		public function init():void
		{
			inEdge1 = outEdge1 = inEdge2 = outEdge2 = NO_EDGE;
		}
		
		//public function set key():void
		//{
			//inEdge1  =  
			//inEdge2  = 
			//outEdge1 = 
			//outEdge2 = 
		//}
			
		public function get key():int
		{
			//return refFace << 24 | incFace << 16 | incVert << 8 | flip;
			
			return inEdge1 << 24 | outEdge1 << 16 | inEdge2 << 8 | outEdge2;
			
//			return inEdge1 + (outEdge1 << 4) + (inEdge2 << 8) + (outEdge2 << 12);
		}
		
		public function flip():void
		{
			inEdge1 ^= inEdge2;
			inEdge2 ^= inEdge1;
			inEdge1 ^= inEdge2;
			
			outEdge1 ^= outEdge2;
			outEdge2 ^= outEdge1;
			outEdge1 ^= outEdge2;
		}
		
		public function copy():FeaturePair
		{
			var f:FeaturePair = new FeaturePair();
			f.inEdge1 = inEdge1;
			f.inEdge2 = inEdge2;
			
			f.outEdge1 = outEdge1;
			f.outEdge2 = outEdge2;
			
			return f;
		}
		
		public function paste(f:FeaturePair):void
		{
			inEdge1  = f.inEdge1;
			inEdge2  = f.inEdge2;
			
			outEdge1 = f.outEdge1;
			outEdge2 = f.outEdge2;
		}
	}
}